<script type="text/javascript">
/// event click on a link
$('a.donvi').live('click', function() {
$('#div_nhanvien').load(
   $(this).attr('href')
, function () {
   $(this).fadeIn(300);
});
return false;
});

$(function () {
	$("#div_tree").jstree({ 
		"ui" : {
			"selected_parent_close" : "select_parent"
		},
		"themes" : {
			"theme" : "default",
			"dots" : true,
			"icons" : false
		},
		"plugins" : [ "themes", "html_data", "ui" ]
	});
});
</script>

<?php
	function printTree($donvis,$cha,$html)
	{
		$row = count($donvis);
		$count= 0;
		foreach ($donvis as $donvi)
		{
			//if($donvi['id']!='') 
			//{
				$count =$count +1;
				if ($donvi['id_cha']==$cha)
				{
					echo "<li>";
					//echo $node['ten'];
					echo $html->link($donvi['tendv'], array('controller'=>'thuocdvs','action'=>'nhanvien',$donvi['id']), array('class'=>'donvi'));
					$id_cha = $donvi['id'];
					echo "<ul>";
					printTree($donvis, $id_cha,$html);
					echo "</ul>";
					echo "</li>";
				}
			//}
		}
	}
?>


<div id="div_tree">

		<ul id='tree'>
			<?php printTree($donvis,0,$html);?>
	 	</ul>
        
</div>

<div id="div_nhanvien"></div>

